
@*logo*@
<div class="logo">
    <img class="logo-image" src="logo_白.png" width="110" height="30" @onclick="gotoHomePage"/>
</div>
@if (@Type)
{
    /*页面标题*/
    <span class="pagename">@PageName</span>
}
else
{
    /*搜索框*/
    <span class="ms-3 flex-sm-fill d-none d-sm-block" style="margin-right: 20px;padding:0 1.5rem ">
        <Search Items="QuestionName"
                IsLikeMatch="true"
                IsAutoClearAfterSearch="true"
                PlaceHolder="请输入题目相关信息"
                OnSearch="@OnSearch"
                SearchButtonColor="Color.Light"/>
    </span>
}

@*用户信息*@
<div class="avater-style" @onclick="gotoPersonPage">
    <Avatar Url="@User.Avatar" Size="Size.ExtraSmall" IsCircle="true"></Avatar>
    <text class="user-name">@User.NickName</text>
</div>

@inject NavigationManager NavigationManager
@code {
    //一定要传入的参数：User,Type；如果需要显示搜索框，则还需传入OnQuestionsFiltered；如果需要显示页面题目，则需传入pagename
    [Parameter]
    public User User{get; set; }//用户信息
    [Parameter]
    public List<Question> Questions { get; set; }
    [Parameter]
    public EventCallback<List<QuestionWithStatus>> OnQuestionsFiltered { get; set; }//传入的参数是一个函数名
    [Parameter]
    public bool Type { get; set; }//false展示搜索框，true展示页面题目
    [Parameter]
    public string PageName { get; set; }//页面题目

    private List<QuestionWithStatus> qs { get; set; } = new List<QuestionWithStatus>();
    private List<string> QuestionName { get; set; } = new List<string>();

    protected override Task OnInitializedAsync()
    {
        base.OnInitializedAsync();
        if (Questions == null)
        {
            Questions = Question.Where(q => true).ToList();
        }
        foreach (var q in Questions)
        {
            QuestionName.Add(q.Title);
        }
        return Task.CompletedTask;
    }

    private void gotoPersonPage()
    {
        //跳转到个人页面
        NavigationManager.NavigateTo("/PersonalPage");
    }
    private Task OnSearch(string searchText)
    {
        //获取题目
        GetAllQuestions(searchText);
        OnQuestionsFiltered.InvokeAsync(qs);
        return Task.CompletedTask;
    }
    public void GetAllQuestions(string searchText)
    {
        //获取题目
        Questions = Questions.Where(q => q.Title.Contains(searchText)||q.Tag.Contains(searchText)||q.Category.Contains(searchText)).ToList();
        
        qs.Clear();
        //获取完成状态
        getALLStatus();
    }

    public void getALLStatus()
    {
        foreach (var q in Questions)
        {
            bool st = false;
            var record=AnswerDetail.Where(a => a.QuestionId == q.Id && a.UserId == User.Id).First();
            if (record != null)
            {
            st = true;
            }
            qs.Add(new QuestionWithStatus(){
                QId=q.Id,
                Title=q.Title,
                Tag=q.Tag,
                Difficulty=q.Difficulty,
                Category=q.Category,
                Status=st,
                DoneTime = q.CreateTime
            });
        }
    }

    public void gotoHomePage()
    {
        NavigationManager.NavigateTo("/HomePage");
    }
}
<style>
    .logo{
        display: flex;
    }
    .logo-title{
        margin: 0 5px;
        font-weight: 700;
        font-size: large;
        font-family: YouYuan, serif;
    }
    .avater-style{
        font-size: 15px;
        align-items: center;
        display: flex;
        justify-content: center;
    }
    .pagename{
        display: flex;
        flex-grow:1 ;
        justify-content: center;
        font-size: 1.5em;
        font-weight: bold
    }
    .user-name{
        border-radius: 5px;
        background-color: rgba(248, 249, 250, 0.23);
        /*color: #555555;*/
        padding: 2px 5px;
        margin-left: 5px
    }
</style>